import Vue from 'vue'
// 导入i18n插件
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)

import en from './locale/en'
import ja from './locale/ja'
import zh from './locale/zh'

// 导入饿了么的语言包
import enLocale from 'element-ui/lib/locale/lang/en'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
import jaLocale from 'element-ui/lib/locale/lang/ja'

// 准备一个字典
const messages = {
  // 环境可以随便写，但是建议保持规范：比如英语就应该是en，日语就应该是ja
  en: {
    ...en,
    ...enLocale
  },
  ja: {
    ...ja,
    ...jaLocale
  },
  zh: {
    ...zh,
    ...zhLocale
  }
}

// 实例化一个i18n对象
const i18n = new VueI18n({
  locale: localStorage.getItem('lang') || 'zh',
  messages
})
export default i18n
